var app = getApp();
// import testMenuData from "../../../pages/utils/testMenuData.js"

Component({
        properties: {
                textOne: {
                        type: String
                },
                inMenuItemData: {
                        type: Array
                }
        },

        data: {
                baseUrl: app.globalData.baseUrl,
                inSelectRightMenuId: 0,

                // 部件列表
                topTabData: [],
                selectTabId: '',

                // 部件候选列表
                selectCandidateId: "",
                candidateDataList: [],

                // 选择的性别
                mSelectGender: app.globalData.selectGender,
                mDontChcekGender: true,

                gPartsMenuDatas: app.globalData.gPartsMenuDatas,

                isInitTime: true
        },

        attached() {
                this.setData({
                        gPartsMenuDatas: app.globalData.gPartsMenuDatas
                })
        },

        methods: {
                /**
                 * 左上候选类型icon点击
                 * @param {*} e 
                 */
                tabItemClick(e) {

                        let tempTabId = e.currentTarget.dataset.data.classifyId
                        console.log(tempTabId)

                        this.setData({
                                selectTabId: tempTabId,
                                mDontChcekGender: e.currentTarget.dataset.data.noCheckGender,
                        })
                        console.log(this.data.mDontChcekGender)

                        this.updateCandidateLay();
                },

                /**
                 * 传入部件类型
                 * @param {*} e 
                 */
                setSelectRightMenuId(e) {
                        this.setData({
                                inSelectRightMenuId: e
                        })
                        let tempTabData = this.data.gPartsMenuDatas.bottomMenuData.find(item => {
                                return item.rightId == e
                        })

                        // isInitTime
                        let tempTabIndex = this.data.isInitTime ? 1 : 0
                        this.setData({
                                topTabData: tempTabData.tabData,
                                mDontChcekGender: tempTabData.tabData[tempTabIndex].noCheckGender,
                                selectTabId: tempTabData.tabData[tempTabIndex].classifyId,
                                isInitTime: false
                        })

                        console.log(this.data.mDontChcekGender)
                        this.updateCandidateLay();
                },

                /**
                 * 更新候选区域
                 */
                updateCandidateLay() {
                        let _self = this;
                        this.setData({
                                mSelectGender: app.globalData.selectGender,
                        })
                        let tempPart = app.globalData.gShowBodyLays.find(item => {
                                return item.partId == this.data.selectTabId
                        })

                        if (tempPart) {
                                this.setData({
                                        selectCandidateId: tempPart.partSrcId ? tempPart.partSrcId : 'part-none',
                                })
                        }
                        
                        let temp = this.data.gPartsMenuDatas[_self.data.selectTabId];
                        this.setData({
                                candidateDataList: temp ? temp : []
                        })

                        console.log(this.data.gPartsMenuDatas)
                        console.log(this.data.candidateDataList)
                },

                /**
                 * 备选部件选择
                 */
                onCandidateClick(e) {
                        console.log(e.currentTarget.dataset.data)
                        let tempData = e.currentTarget.dataset.data
                        this.triggerEvent("onCandidateClick", {
                                classifyId: this.data.selectTabId,
                                selectItem: tempData
                        });

                        let tempPart = app.globalData.gShowBodyLays.find(item => {
                                return item.partId == this.data.selectTabId
                        })

                        if (tempPart) {
                                this.setData({
                                        selectCandidateId: tempPart.partSrcId,
                                })
                        }
                }
        },
})